﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Services;
using OnlineAuction_GL.Local;

namespace OnlineAuction_GL
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public int[] AuthenticateUser(string username, string password, string server)
        {
            int[] result = new int[2];
            
            string serverListPath = Server.MapPath("~/App_Data/ServerList.txt");
            var query = from l in File.ReadAllLines(serverListPath)
                        let parts = l.Split(';')
                        where parts[0] == server
                        select new { Server = parts[0], Url = parts[1] };
            if (query.Count() == 0) return result;
            
            Local.Service1 proxy = new Local.Service1();
            proxy.Url = query.First().Url; //Đổi url của Local Web Service đã add
            result = proxy.AuthenticateUser(username, password, server);
            return result;
        }
    }
}
